package com.iwomy.envpro.platform.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.iwomy.envpro.platform.entity.AirMonitorEquipmentEntity;
import com.iwomy.envpro.platform.entity.AirSiteEntity;
import com.iwomy.envpro.platform.mapper.AirMonitorEquipmentMapper;
import com.iwomy.envpro.platform.service.AirMonitorEquipmentService;
import com.iwomy.envpro.platform.service.AirSiteService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 监测设备管理
 *
 * @author pig
 * @date 2023-08-28 10:12:58
 */
@Service
public class AirMonitorEquipmentServiceImpl extends ServiceImpl<AirMonitorEquipmentMapper, AirMonitorEquipmentEntity> implements AirMonitorEquipmentService {
	@Resource
	private AirSiteService airSiteService;
	@Override
	public Page<AirMonitorEquipmentEntity> getAirMonitorEquipmentList(Page page,Long id) {
		Page airSiteList = airSiteService.getAirSiteList(new Page(), id);
		List<AirSiteEntity> records = airSiteList.getRecords();
		List<Long> airSiteIds = records.stream().map(AirSiteEntity::getId).collect(Collectors.toList());

		if(ObjectUtil.isEmpty(airSiteIds))return  new Page();

		LambdaQueryWrapper<AirMonitorEquipmentEntity> queryWrapper = Wrappers.<AirMonitorEquipmentEntity>lambdaQuery();
		return this.getBaseMapper().selectPage(page,queryWrapper.in(AirMonitorEquipmentEntity::getSiteId,airSiteIds));
	}
}